package com.hrms.doctor.controller;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.hrms.patient.core.controller.BaseController;
import com.hrms.patient.core.domain.AjaxResult;
import com.hrms.patient.core.page.TableDataInfo;
import com.hrms.doctor.domain.vo.ScheduleBriefVo;
import com.hrms.doctor.domain.vo.ScheduleVo;
import com.hrms.doctor.service.ScheduleService;
import com.hrms.doctor.domain.Schedule;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

@RestController
@Api(tags = "随访接口")

public class ScheduleController extends BaseController {
    @Autowired
    ScheduleService scheduleService;
/*
    @GetMapping("/schedules")
    public AjaxResult list(String doctorName,String patientName){
        scheduleService.selectSchedule(doctorName,patientName);
        return success();

    }*/

    //修改随访记录'
    @ApiOperation("修改随访")
    @PutMapping("/schedule")
    public AjaxResult updateSchedule(@RequestBody Schedule schedule){

        return toAjax(scheduleService.updateSchedule(schedule));
    }
    //新增随访
    @ApiOperation("新增随访")
    @PostMapping("/schedule")
    //TODO:新增DTO
    public  AjaxResult insertSchedule(@Validated @RequestBody Schedule schedule){

        return toAjax(scheduleService.insertSchedule(schedule));
    }
    //删除记录
    @ApiOperation("删除随访")
    @DeleteMapping("/schedule/{list}")
    public AjaxResult deleteSchedule(@PathVariable List<Long> list){
            return toAjax(scheduleService.deleteSchedule(list));
    }
    /*
    //根据医生ID删除（删除医生把关联也删除）
    @DeleteMapping("/schedules/{id}")
    public void deleteScheduleById(@PathVariable Long id){
        scheduleService.deleteScheduleById(id);
    }*/
    //医生随访数目
    /*@ApiOperation("医生的随访数目")
    @GetMapping("/schedules/doctorsCount/{id}")
    public AjaxResult selectCountByDoctorId(@PathVariable Long id){
        Integer rs=scheduleService.selectCountByDoctorId(id);
        return success(rs);
    }
    //患者随访记录数目
    @ApiOperation("患者的随访数目")
    @GetMapping("/schedules/patientCount/{id}")
    public AjaxResult selectCountByPatientId(@PathVariable Long id){
        Integer rs=scheduleService.selectCountByPatientId(id);
        return success(rs);
    }*/
    //(小程序)医生查找随访记录
    @ApiOperation("通过医生ID查找拥有随访")
    @GetMapping("/user/schedule/doctor/{id}")
    public AjaxResult selectPatientById(@PathVariable Long id){
        List<ScheduleVo> rs=scheduleService.selectPatientById(id);
        return success(rs);
    }
    //(管理系统)医生查找随访记录
    @GetMapping("/schedule/doctor/{id}")
    public TableDataInfo schedulePage(@PathVariable Long id,String patientName){
        startPage();
        List<ScheduleVo> rs=scheduleService.selectPatientByIdWithName(id,patientName);
        return getDataTable(rs);
    }

    //医生通过患者列表查找随访记录
    @ApiOperation("通过患者ID查找拥有随访")
    @GetMapping("/user/schedule/patient/{id}")
    public AjaxResult selectDoctorById(@PathVariable Long id){
        List<ScheduleVo> rs=scheduleService.selectDoctorById(id);

        return success(rs);
    }

    //指定天数的随访日程
    @ApiOperation("今日随访日程")
    @GetMapping("/user/schedule/day")
    public AjaxResult getByDay(@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime begin,@DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")LocalDateTime end,String deptName){
       List<ScheduleBriefVo> list=scheduleService.getScheduleByTime(begin,end,deptName);
        return success(list);
    }

    //从随访简介查看随访详细
    @GetMapping("/user/schedule/day/{id}")
    public AjaxResult getInfoByScheduleId(@PathVariable Long id){
        ScheduleVo scheduleVo=scheduleService.getInfoByScheduleId(id);
        return success(scheduleVo);
    }
}
